package com.example.liyuezhao.intent;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.Button;
import android.telephony.PhoneNumberUtils;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
/*
        Button dialer=(Button)findViewById(R.id.Button01);
        dialer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(Intent.ACTION_DIAL,Uri.parse("tel://114"));
                startActivity(intent);
            }
        });
        */
        final EditText phoneNum = (EditText) findViewById(R.id.phoneNum);
        final Button button = (Button) findViewById(R.id.Button01);
        button.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View b) {
                //Intent <Intent_name>=new Intent (<Action>,<Data>);
                String call = phoneNum.getText().toString();
                if (PhoneNumberUtils.isGlobalPhoneNumber(call)) {
                    Intent I = new Intent(Intent.ACTION_CALL, Uri.parse("tel://" + call));
                    startActivity(I);
                } else {
                    Toast.makeText(MainActivity.this,
                            R.string.notify_incorrect_phonenum, Toast.LENGTH_LONG).show();
                }
            }
        });
    }
}
